# -*- codeing = utf-8 -*-
# @Time : 2022/2/19 20:17
# @File : database.py
# @Software : PyCharm
import MySQLdb

class dataoperator():
    def __init__(self):
        self.db = MySQLdb.connect("localhost", "root", "root", "face", charset='utf8')
        self.cursor = self.db.cursor()

    def insertperson(self, name, sex, sector):
        sql = "insert into member values("+str(self.getpersoncount())+", '"+name+"', '"+sex+"','"+sector+"')"
        self.cursor.execute(sql)
        self.db.commit()


    def getpersoncount(self):
        sql = "select count(id) from member"
        self.cursor.execute(sql)
        return self.cursor.fetchall()[0][0]

    def get_recognize_info(self):
        sql = "select id,name from member"
        FACE_LABEL = {}
        self.cursor.execute(sql)
        resource = self.cursor.fetchall()
        for row in resource:
            id = row[0]
            name = row[1]
            FACE_LABEL[id] = name

        return FACE_LABEL

# d = dataoperator()
# d.__init__()
# print(d.get_recognize_info())